package com.sdp.irrigation.storage.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.core.KafkaTemplate;

import com.sdp.irrigation.kafka.consumer.KafkaConsumerManager;
import com.sdp.irrigation.kafka.producer.KafkaProducer;


@Configuration
public class KafkaConfiguration {

	@SuppressWarnings("rawtypes")
	@Autowired
	private ConcurrentKafkaListenerContainerFactory factory;

	@Autowired
	private KafkaListenerEndpointRegistry register;
	
	@Autowired
	private KafkaTemplate<String, String> kafkaTemplate;

	@Bean
	public KafkaConsumerManager kafkaConsumerManager() {
		factory.setAutoStartup(false);
		return new KafkaConsumerManager(factory, register);
	}
	
	@Bean
	public KafkaProducer kafkaProducer()
	{
		return new KafkaProducer(kafkaTemplate);
	}
	
}
